// pages/index2/index2.js
Page({

  data: {
    detail_img_list: [],
    list: [],
    demo_list: ["http://pili-vod.xuexi.haizb.cn/6b6f5202410241001521165.png","http://pili-vod.xuexi.haizb.cn/513c8202410241001471553.png","http://pili-vod.xuexi.haizb.cn/e8635202410241001249699.png","http://pili-vod.xuexi.haizb.cn/7d998202410240958479903.png", "http://pili-vod.xuexi.haizb.cn/47d7e202410241001094421.png", "http://pili-vod.xuexi.haizb.cn/e629e202410241001177747.png" ]
  },
  onLoad(options) {
    this.getConfigNet();
    this.onPullDownRefresh();
  },
  onPullDownRefresh() {
    this.getNet();
  },
  getConfigNet() {
    var that = this;
    var detail_img_list = wx.getStorageSync('detail_img_list');
    var index2_share = wx.getStorageSync('index2_share');
    that.setData({
      "detail_img_list": detail_img_list,
      "index2_share": index2_share
    })
    wx.request({
      url: 'https://api.dianshiyexiao.com/weapp/config',
      method: 'POST',
      success(res) {
        console.log(res.data.data)
        var index_img_list = [];
        var detail_img_list = [];
        var index1_share = "";
        var index2_share = "";
        res.data.data.forEach(element => {
          console.log(element)
          if (element.type == "index_img") {
            index_img_list.push(element.value)
          }
          if (element.type == "detail_img") {
            detail_img_list.push(element.value)
          }
          if (element.type == "index1_share") {
            index1_share = element.value;
          }
          if (element.type == "index2_share") {
            index2_share = element.value;
          }
        });
        wx.setStorageSync("index_img_list", index_img_list)
        wx.setStorageSync("detail_img_list", detail_img_list)
        wx.setStorageSync("index1_share", index1_share)
        wx.setStorageSync("index2_share", index2_share)
        that.setData({
          "detail_img_list": detail_img_list,
          "index2_share": index2_share
        })
      },
      fail(error) {
        console.log(error)
      },
    })
  },
  getNet() {
    var that = this;
    wx.request({
      url: 'https://api.dianshiyexiao.com/weapp/company/list',
      method: 'POST',
      success(res) {
        wx.stopPullDownRefresh()
        console.log(res.data)
        that.setData({
          list: res.data.data.list,
        })
      },
      fail(error) {
        wx.stopPullDownRefresh()
        console.log(error)
      },
    })
  },
  goDetail(e) {
    console.log(e)
    console.log(e.currentTarget.dataset.cid)
    wx.navigateTo({
      url: '/pages/votedetail/votedetail?id=' + e.currentTarget.dataset.cid,
    })
  },
  onShareAppMessage() {
    var that = this;
    return {
      title: ("雨林好物,投票开始啦!"),
      path: '/pages/index2/index2',
      imageUrl: that.data.index2_share
    }
  },
  onShareTimeline() {
    return {
      title: ("雨林好物,投票开始啦!"),
      path: '/pages/index2/index2',
    }
  }
})